package ControlLayer;

import java.sql.Date;
import java.util.ArrayList;

import DBLayer.*;
import ModelLayer.*;



public class CtrOffer {
	
	DBOffer dbOffer;
	DBOfferLabour dbOfferLabour;
	
	public CtrOffer(){
		dbOffer = new DBOffer();
	}

	
	public void addOfferLabour(Offer offer, double price, int amount, int labourId, String name, int offerLabourId)
	{
		offer.addOfferLabour(price, amount, labourId, name, offerLabourId);

	}
	public void addOfferMaterial(Offer offer, double price, int quantity, String type,int materialId,String name, int offerMaterialId)
	{
		offer.addOfferMaterial(price, quantity, type, materialId, name, offerMaterialId);

	}
	
	
	public void removeOfferLabour(Offer offer, int labourId){
		offer.removeOfferLabour(labourId);
	}
	
	
	public ArrayList<Offer> getAllOffers(){
		return dbOffer.getAllOffers();
	}
	
	//public ArrayList<Sales> getAll_byCustomerID(int cid){
	//	return dbSales.getAll_byCustomerID(cid);
	//}
	
	
	public Offer findOffer(int offerId) {
		return dbOffer.findOffer(offerId);
	}	
	
	
	public int deleteOffer(int offerId){
		return dbOffer.deleteOffer(offerId);
	}
	
	
	public int updateOffer(int offerId, int customerId, String date)
	{
		Offer offer = new Offer(offerId,customerId, date);
		return dbOffer.updateOffer(offer);
	}
	
	public void createOffer(int offerId,int customerId, String date)
    {    
      Offer offerObj = new Offer();
    
      offerObj.setOfferId(offerId);
      offerObj.setCustomerId(customerId);
      offerObj.setDate(date);
     

         try{
          DbConnection.startTransaction();
          
          DBOffer dbOffer = new DBOffer();
          dbOffer.insertOffer(offerObj);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	
}
